$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/brandvital/list',
        datatype: "json",
        colModel: [
			// { label: 'ID', name: 'orderId', index: 'order_id',align: "center", width: 100, key: true,
			// 	formatter:function(value,options,rowData){
			// 		return "<a onclick=vm.openInfo('"+value+"')>"+value+"</a>";
			// 	}
			// },
            { label: '品牌ID', name: 'brandId', index: 'brandId',align: "center", width:80 },
			{ label: '品牌名称', name: 'brandName', index: 'brandName',align: "center", width: 80 },
			{ label: '订单数(已支付)', name: 'orderCount', index: 'orderCount',align: "center", width: 80 },
			{ label: '总金额', name: 'orderAmount', index: 'orderAmount',align: "center", width: 80 },
			{ label: '用户数', name: 'effectiveCount', index: 'effectiveCount',align: "center", width: 80 },
			//{ label: '设为微站数', name: 'brandCount', index: 'brandCount',align: "center", width: 80 },
            { label: '会员数', name: 'vipCount', index: 'vipCount',align: "center", width: 80},
			{ label: '文章数', name: 'articleCount', index: 'articleCount',align: "center", width: 80 },
			{ label: '视频数', name: 'videoCount', index: 'videoCount',align: "center", width: 80},
        ],
		viewrecords: true,
        height: "100%",
        rowNum: 20,
		rowList : [20,50,100],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });


	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>请选择公众号</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bOrderInfo: {},
		q:{
			startDate:null,
			endDate:null,
			gzhCode:'',
			orderCol:'effective_count',
			brandId:null
		}
	},
	// 页面加载完毕后触发的事件
	mounted() {
		var vm = this;
		vm.q.startDate = vm.todayDate(); // 默认显示为当天时间
		vm.q.endDate = vm.todayDate();
	},
	methods: {
		todayDate: function() {
			let now = new Date();

			let y = now.getFullYear(); //年
			let m = now.getMonth() + 1 + ''; //月
			let d = now.getDate() + ''; //日

			m = m.length == 1 ? '0' + m : m;
			d = d.length == 1 ? '0' + d : d;
			return y + '-' + m + '-' + d;
		},
		query: function () {
			vm.reload();
		},
		openInfo: function (e) {
		},
		getInfo: function(orderId){

		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                page:page,
				postData:{"brandId":vm.q.brandId,"gzhCode":vm.q.gzhCode,"orderCol":vm.q.orderCol,"startDate":vm.q.startDate,"endDate":vm.q.endDate}
            }).trigger("reloadGrid");
		}
	}
});
